<?PHP
session_start();

include "./php/url.php";
include_once "./php/ini.php";

if (( isset ($_POST["login"])) && ( isset ($_POST["connexion"])))
{
    $login = $_POST['login'];
    $pass = $_POST['pass'];
    dbconnect();

    global $log_tmp;
    global $log_tmp2;
    global $mdp_tmp;
    global $mdp_tmp2;

    //from login
    $requete = "SELECT * FROM users WHERE nom_user='".$login."';";
    $req = mysql_query($requete);
    $r = mysql_fetch_assoc($req);
    $log_tmp = $r['nom_user'];
    $mdp_tmp = $r['pass_user'];

    //from pass
    $requete = "SELECT * FROM users WHERE pass_user='".$pass."';";
    $req = mysql_query($requete);
    $r2 = mysql_fetch_assoc($req);
    $log_tmp2 = $r2['nom_user'];
    $mdp_tmp2 = $r2['pass_user'];

    //compare
    if (($log_tmp != "") && ($mdp_tmp != "") && ($log_tmp == $log_tmp2) && ($mdp_tmp == $mdp_tmp2))
    {
        $sql = "SELECT * FROM users WHERE nom_user='".$login."';";
        $requete = mysql_query($sql);
        if (!$requete)
        {
            echo "SQL error : ", $sql;
            exit ;
        }
        else
        {
            while ($tab = mysql_fetch_assoc($requete))
            {
                if ($tab['compte_active'] == 1)
                {
                    $_SESSION["login"] = $_POST["login"];
                    $_SESSION["id_user"] = $tab['id_user'];

                    if ( isset ($_POST["remember"]))
                    {
                        setcookie("goldname", $_SESSION["login"], time()+60*60*24*61);
                    }
                    $query = "UPDATE `users` SET `online` = '1' WHERE `users`.`id_user` = '".$_SESSION['id_user']."' LIMIT 1 ;";
                    $result = mysql_query($query);
                    if (!$result)
                    {
                        echo "SQL error : ", $query;
                        exit ;
                    }
                }
                else
                {
                    echo '<script language="Javascript">

document.location.replace("'.$url.'");

</script>';
                }
            }
        }
    }
    else
    {
        echo '<script language="Javascript">

document.location.replace("'.$url.'");

</script>';
    }

    dbclose();
}



if (! isset ($_SESSION['login']) && isset ($_GET['id']))
{
    echo '<script language="Javascript">
var _url = "'.$url.'?id='.$_GET['id'].'";
document.location.replace(_url);

</script>';
}
else if (! isset ($_SESSION['login']))
{
    echo '<script language="Javascript">

document.location.replace("'.$url.'");

</script>';
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
    <head>
        <title>Last Life</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <script type="text/javascript" language="javascript" src="./js/jquery-1.3.2.min.js"></script>
        <script type="text/javascript" language="javascript" src="./js/jquery-ui-1.7.1.custom.min.js"></script>
		<!-- <script type="text/javascript" language="javascript" src="./js/ui.dialog.js"></script> -->


        <script type="text/javascript" language="javascript" src="./js/function.js"></script>
        <script type="text/javascript" src="./ajaxfileupload/ajaxfileupload.js"></script>

		<!-- <link rel='stylesheet' href='css/ui/styleUi.css' type='text/css' media='screen' />		 -->
		<link rel='stylesheet' href='css/style.css' type='text/css' media='screen' />

        <script type="text/javascript">
            var _global_nom;
            var _global_id_user;
            var _global_url;
            //_global_url = "http://dev.citu.fr/lastlife/";
            _global_url = "http://localhost:8888/lastlifeDev/";

            var _global_chat = new Array;
        </script>
    </head>

    <body onload="init();">
	
        <div class="b_line">
            <div class="t1">
                <?PHP
                echo '<span class="l1"><a href="'.$url.'" title="Accueil">Last Life</a></span>';
				// LogOut	
	            $deco = ( isset ($_SESSION['login']))?'<input id="btn_deco" type="submit" name="deco" value="Logout">':'';
	            echo "<div class=\"big1\">";
	            echo '<form method="POST" action="index.php"> '.$deco.' </form>';
                ?>
            </div>
        </div>

		<div id="content">
	

			<!-- VIRTOOLS PLAYER -->
            <OBJECT id="virtool" style=" position: relative; float: left;" 
				CLASSID="CLSID:D4323BF2-006A-4440-A2F5-27E3E7AB25F8" ID="Virtools" WIDTH="640" HEIGHT="480"
				CODEBASE="http://a532.g.akamai.net/f/532/6712/5m/virtools.download.akamai.com/6712/player/install/installer.exe#Version=4,0,0,26">
	            <PARAM NAME="SRC" VALUE="lastLife.vmo"><param name="KeepKeyBoard" value="0">
	            <EMBED SRC="lastlife.vmo" TYPE="application/x-virtools" PLUGINSPAGE="http://player.virtools.com/" WIDTH="640" HEIGHT="480" NAME="Virtools" KeepKeyBoard="0">
	            </EMBED>
            </OBJECT>	
			<!-- END VIRTOOLS PLAYER -->
			

			<div id="interface">
				<!-- mais a quoi sert ce script ??? -->
		        <script type="text/javascript"> _identification("<?php  echo $_SESSION["login"] ?>"); </script>
	      

				<!-- VITESSE -->
		        <div id="vitesse">
					<span>Vitesse : </span>
		            <input type="button" onclick="changeVitesse(20); return false;" value="x20" />
		        </div>
				<!-- END VITESSE -->
			
				<p>Partagez votre vie : http://dev.citu.fr/lastlife/main.php?id=<?php echo $_SESSION['id_user'] ?></p>
	
				<!-- TAG -->
				<div id="getTag">
					<input type='button' value='Get tag' onclick='_getUserTag("<?php echo $_SESSION['id_user'] ?>"); return false;' />
			        <div class="cloud"></div>
				</div>
				<!-- END TAG -->

				<!-- SEARCH TAG -->
		        <form onsubmit="_searchTag(); return false;">
		            <input type="text" size=15 id='searchTag'><input type='submit' value='Search'>
		        </form>
				<!-- END SEARCH TAG -->
	
	
		        <br/>
		        <?PHP
		        echo "<input type='button' value='Get info' onclick='V2JS_getCamInfo(1); return false;' />";
		        if ( isset ($_GET['id']))
		        {
		            echo "<script type='text/javascript'> V2JS_getCamInfo(".$_GET['id']."); </script>";
		        }
		        ?>
	
	
		        <input type="button" onclick="V2JS_sendStat('1!15!1'); return false;" value="Stats" />
		        <div id="div_chat"></div>
	
		    </div>
			<div class="clear"></div>

			<div id="camInfo"></div>
	
			<div id="upload_message"></div>
		</div>
    </div>
       

    </body>
</html>
